(function(vue) {
  "use strict";
  const iconpath = "/assets/uniicons.ab33ac77.ttf";
  const _sfc_main$2 = vue.defineComponent({
    name: "uni-navbar",
    props: {
      title: new UTSJSONObject({
        type: String,
        default: ""
      }),
      isLeft: new UTSJSONObject({
        type: Boolean,
        default: false
      })
    },
    data() {
      return {
        statusBarHeight: 0
      };
    },
    computed: new UTSJSONObject({
      navbarStyle() {
        return "margin-top:".concat(this.statusBarHeight, "px");
      },
      unicode() {
        return "";
      }
    }),
    created() {
      uni.loadFontFace({
        global: false,
        family: "UniIconsFontFamily",
        source: iconpath,
        success() {
        },
        fail(err) {
          uni.__log__("log", "at components/uni-navbar-lite/uni-navbar-lite.uvue:51", err);
        }
      });
      const sys = uni.getSystemInfoSync();
      const statusBarHeight = sys.statusBarHeight;
      this.statusBarHeight = statusBarHeight;
    },
    mounted() {
      setTimeout(() => {
        uni.setNavigationBarColor({
          frontColor: "#000000",
          backgroundColor: "#ffffff"
        });
      }, 100);
    },
    methods: new UTSJSONObject({
      back() {
        var _a;
        (_a = getApp().globalData.webviewContext) === null || _a === void 0 ? void 0 : _a.back();
      }
    })
  });
  const _style_0$2 = { "uni-icons": { "": { "!fontFamily": "UniIconsFontFamily", "fontSize": 22, "fontStyle": "normal", "color": "#333333" } }, "uni-navbar": { "": { "borderTopWidth": 1, "borderRightWidth": 1, "borderBottomWidth": 1, "borderLeftWidth": 1, "borderTopStyle": "solid", "borderRightStyle": "solid", "borderBottomStyle": "solid", "borderLeftStyle": "solid", "borderTopColor": "#eeeeee", "borderRightColor": "#eeeeee", "borderBottomColor": "#eeeeee", "borderLeftColor": "#eeeeee", "backgroundColor": "#ffffff" } }, "uni-navbar-inner": { "": { "position": "relative", "display": "flex", "flexDirection": "row", "justifyContent": "space-between", "height": 45 } }, "left-content": { "": { "display": "flex", "justifyContent": "center", "alignItems": "center", "width": 45, "height": "100%" } }, "right-content": { "": { "display": "flex", "justifyContent": "center", "alignItems": "center", "width": 45, "height": "100%" } }, "uni-navbar-content": { "": { "position": "absolute", "height": "100%", "top": 0, "bottom": 0, "left": 45, "right": 45, "display": "flex", "flexDirection": "row", "justifyContent": "center", "alignItems": "center" } }, "is-left": { "": { "justifyContent": "flex-start" } }, "@FONT-FACE": [{ "fontFamily": "UniIconsFontFamily", "src": "url('/assets/uniicons.ab33ac77.ttf')" }] };
  const _export_sfc = (sfc, props) => {
    const target = sfc.__vccOpts || sfc;
    for (const [key, val] of props) {
      target[key] = val;
    }
    return target;
  };
  function _sfc_render$1(_ctx, _cache, $props, $setup, $data, $options) {
    return vue.openBlock(), vue.createElementBlock("view", { class: "uni-navbar" }, [
      vue.createElementVNode("view", {
        class: "uni-navbar-inner",
        style: vue.normalizeStyle($options.navbarStyle)
      }, [
        vue.createElementVNode("view", {
          class: "left-content",
          onClick: _cache[0] || (_cache[0] = (...args) => $options.back && $options.back(...args))
        }, [
          vue.createElementVNode("text", { class: "uni-icons" }, vue.toDisplayString($options.unicode), 1)
        ]),
        vue.createElementVNode("view", {
          class: vue.normalizeClass(["uni-navbar-content", { "is-left": $props.isLeft }])
        }, [
          vue.renderSlot(_ctx.$slots, "default", {}, () => [
            vue.createTextVNode(vue.toDisplayString($props.title), 1)
          ])
        ], 2),
        vue.createElementVNode("view", { class: "right-content" }, [
          vue.renderSlot(_ctx.$slots, "right")
        ])
      ], 4)
    ]);
  }
  const __easycom_0 = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["render", _sfc_render$1], ["styles", [_style_0$2]]]);
  function resolveEasycom(component, easycom) {
    return typeof component === "string" ? easycom : component;
  }
  const jsLongPressImg = '\n	!function(document) { \n		function clearLongPressTimer(timer) {\n			clearTimeout(timer);\n		}\n		if(window.handleListen){\n			window.removeEventListener("touchstart", window.handleListen);\n		}else{\n			window.handleListen= function(e) {\n				let timer = setTimeout(() => {\n					if (e.target.tagName === "IMG") {\n						uni.webView.postMessage({\n							data: {  \n								type: \'JsGetString\',\n								action: \'longPressImg\',\n								query: {\n									src: e.target.src,\n								}\n							}  \n						}) \n					}\n				}, 500);\n				window.addEventListener("touchend", function () {\n					clearLongPressTimer(timer);\n				});\n				window.addEventListener("touchmove", function () {\n					clearLongPressTimer(timer);\n				});\n			};\n		}\n		window.addEventListener("touchstart", window.handleListen);\n	}(document)\n	';
  const jsGetTitle = "\n	!function(document) {  \n		var title = document.title;  \n		uni.webView.postMessage({\n			data: {  \n				type: 'JsGetString',\n				action: 'getPageTitle',\n				query: {\n					pageTitle: title\n				}\n			}  \n		})  \n	}(document)  \n	";
  const fs = uni.getFileSystemManager();
  const _sfc_main$1 = vue.defineComponent(new UTSJSONObject({
    data() {
      return {
        src: "http://192.168.1.57:8080",
        // src: 'https://wap.tuns.com.cn',
        webviewElement: null,
        pageTitle: "",
        touchStartX: 0,
        touchEndX: 0,
        uniWebviewJs: ""
        // uni.webview.1.5.5.js
      };
    },
    onReady() {
      var _a;
      fs.readFile({
        encoding: "utf-8",
        filePath: "static/uni.webview.1.5.5.js",
        success: (res) => {
          this.uniWebviewJs = res.data;
        },
        fail: (res) => {
          uni.__log__("log", "at pages/index/index.uvue:37", "readFile失败", res);
        }
      });
      getApp().globalData.webviewContext = uni.createWebviewContext("web-view", this);
      this.webviewElement = uni.getElementById("web-view");
      (_a = this.webviewElement) === null || _a === void 0 ? void 0 : _a.setAttribute("src", this.src);
      const deviceInfo = uni.getDeviceInfo();
      uni.getSystemInfo(new UTSJSONObject({
        success: (systemInfo) => {
          var _a2;
          const stringDeviceInfo = UTS.JSON.stringify(new UTSJSONObject(Object.assign(Object.assign({}, deviceInfo), systemInfo)));
          (_a2 = getApp().globalData.webviewContext) === null || _a2 === void 0 ? void 0 : _a2.evalJS("localStorage.setItem('deviceInfo', '".concat(stringDeviceInfo, "')"));
        }
      }));
    },
    methods: new UTSJSONObject({
      touchStart(event) {
        this.touchStartX = event.touches[0].pageX;
      },
      touchMove(event) {
        this.touchEndX = event.touches[0].pageX;
      },
      touchEnd(event) {
        var _a;
        uni.__log__("log", "at pages/index/index.uvue:66", "touchEnd结束,起始x", this.touchStartX);
        if (this.touchStartX < this.touchEndX - 50 && this.touchStartX < 15) {
          (_a = getApp().globalData.webviewContext) === null || _a === void 0 ? void 0 : _a.back();
        }
      },
      /**
       * H5传递过来的消息
       */
      message(event) {
        const params = event.detail.data[0];
        uni.__log__("log", "at pages/index/index.uvue:80", "H5通信参数", UTS.JSON.stringify(params));
        const type = params.type;
        const action = params.action;
        const query = params.query;
        const tp = params.tp;
        if (type == "Invoke") {
          this.InvokeHanlder(action, query, tp);
        }
        if (type == "JsGetString") {
          this.InvokeJsString(action, query);
        }
      },
      /**
       * type 类型为 Invoke(h5调用原生方法) 的处理
       * 问题点：h5无法通过postMessage传递函数过来
       * 解决方法：通过evalJS 执行 h5 挂在window上的函数达到回调的效果
       */
      InvokeHanlder(action, query = new UTSJSONObject({}), tp = null) {
        switch (action) {
          case "appUpdate":
            const res = uni.downloadFile({
              url: query.url,
              success: (res2) => {
                uni.installApk({
                  filePath: res2.tempFilePath
                });
              }
            });
            res.onProgressUpdate((result) => {
              var _a;
              (_a = getApp().globalData.webviewContext) === null || _a === void 0 ? void 0 : _a.evalJS("InvokeOnProgress".concat(tp, "(").concat(UTS.JSON.stringify(result), ")"));
            });
            break;
          case "getLocation":
            uni.getLocation(new UTSJSONObject({
              success: (res2) => {
                var _a;
                (_a = getApp().globalData.webviewContext) === null || _a === void 0 ? void 0 : _a.evalJS("InvokeSuccess".concat(tp, "(").concat(UTS.JSON.stringify(res2), ")"));
              }
            }));
            break;
        }
      },
      /**
       * 加载第三方页面 第三方和我们的通信
       * 问题点：第三方我们没法改他们的代码
       * 解决方法：通过evalJS 注入我们的代码
       */
      InvokeJsString(action, query = new UTSJSONObject({})) {
        switch (action) {
          case "getPageTitle":
            this.pageTitle = query.pageTitle;
            break;
        }
      },
      /**
       * webview在加载失败时触发
       */
      error(event) {
        uni.__log__("log", "at pages/index/index.uvue:214", "webview-error", UTS.JSON.stringify(event.detail));
        if (event.detail.errCode == 100002) {
          uni.showModal(new UTSJSONObject({
            title: "提示",
            content: "页面加载失败，请确定是否重新加载，取消将会返回上一页",
            success: (res) => {
              var _a, _b;
              if (res.cancel) {
                (_a = getApp().globalData.webviewContext) === null || _a === void 0 ? void 0 : _a.back();
              }
              if (res.confirm) {
                (_b = getApp().globalData.webviewContext) === null || _b === void 0 ? void 0 : _b.back();
              }
            }
          }));
        }
      },
      /**
       * webview在加载时触发，webview里每次的路由跳转都会触发（spa单页router跳转不会触发）
       */
      loading(event) {
        uni.__log__("log", "at pages/index/index.uvue:238", "webview-loading", UTS.JSON.stringify(event.detail));
      },
      /**
       * webview在加载完成触发，webview里每次的路由跳转都会触发（spa单页router跳转不会触发）
       */
      load(event) {
        var _a, _b;
        uni.__log__("log", "at pages/index/index.uvue:244", "webview-load", UTS.JSON.stringify(event.detail));
        this.pageTitle = "";
        if (!event.detail.src.includes("wap.tuns.com.cn") && !event.detail.src.includes("192.168")) {
          (_a = getApp().globalData.webviewContext) === null || _a === void 0 ? void 0 : _a.evalJS(this.uniWebviewJs + jsGetTitle);
        }
        (_b = getApp().globalData.webviewContext) === null || _b === void 0 ? void 0 : _b.evalJS(this.uniWebviewJs + jsLongPressImg);
      },
      /**
       * webview内点击了可下载链接时触发
       */
      download(event) {
        uni.__log__("log", "at pages/index/index.uvue:288", "webview-download", UTS.JSON.stringify(event.detail));
        uni.showModal(new UTSJSONObject({
          content: "下载链接: " + event.detail.url + "\n文件大小: " + event.detail.contentLength / 1024 + "KB",
          showCancel: false
        }));
      }
    })
  }));
  const _style_0$1 = { "tuns-view-containter": { "": { "display": "flex", "flexDirection": "column", "height": "100%", "width": "100%", "overflow": "hidden" } }, "title-bar": { "": { "flexShrink": 0 } }, "uni-flex-item": { "": { "flex": 1 } } };
  function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
    const _component_uni_navbar_lite = resolveEasycom(vue.resolveDynamicComponent("uni-navbar-lite"), __easycom_0);
    return vue.openBlock(), vue.createElementBlock("view", {
      class: "tuns-view-containter",
      onTouchstart: _cache[5] || (_cache[5] = (...args) => $options.touchStart && $options.touchStart(...args)),
      onTouchmove: _cache[6] || (_cache[6] = (...args) => $options.touchMove && $options.touchMove(...args)),
      onTouchend: _cache[7] || (_cache[7] = (...args) => $options.touchEnd && $options.touchEnd(...args))
    }, [
      $data.pageTitle ? (vue.openBlock(), vue.createBlock(_component_uni_navbar_lite, {
        key: 0,
        class: "title-bar",
        title: $data.pageTitle
      }, null, 8, ["title"])) : vue.createCommentVNode("", true),
      vue.createElementVNode("web-view", {
        id: "web-view",
        class: "uni-flex-item",
        style: { "pointer-events": "auto" },
        horizontalScrollBarAccess: false,
        verticalScrollBarAccess: false,
        onMessage: _cache[0] || (_cache[0] = (...args) => $options.message && $options.message(...args)),
        onError: _cache[1] || (_cache[1] = (...args) => $options.error && $options.error(...args)),
        onLoading: _cache[2] || (_cache[2] = (...args) => $options.loading && $options.loading(...args)),
        onLoad: _cache[3] || (_cache[3] = (...args) => $options.load && $options.load(...args)),
        onDownload: _cache[4] || (_cache[4] = (...args) => $options.download && $options.download(...args))
      }, null, 32)
    ], 32);
  }
  const PagesIndexIndex = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["render", _sfc_render], ["styles", [_style_0$1]]]);
  __definePage("pages/index/index", PagesIndexIndex);
  const _sfc_main = vue.defineComponent(new UTSJSONObject({
    globalData: new UTSJSONObject({
      webviewContext: null
      // web-view 组件的上下文对象，用于操作 web-view 的行为
    }),
    onLaunch: function() {
      uni.__log__("log", "at App.uvue:11", "App Launch");
    },
    onShow: function() {
      uni.__log__("log", "at App.uvue:14", "App Show");
    },
    onHide: function() {
      uni.__log__("log", "at App.uvue:17", "App Hide");
    },
    onExit: function() {
      uni.__log__("log", "at App.uvue:45", "App Exit");
    }
  }));
  const _style_0 = { "uni-row": { "": { "flexDirection": "row" } }, "uni-column": { "": { "flexDirection": "column" } } };
  const App = /* @__PURE__ */ _export_sfc(_sfc_main, [["styles", [_style_0]]]);
  const __global__ = typeof globalThis === "undefined" ? Function("return this")() : globalThis;
  __global__.__uniX = true;
  function createApp() {
    const app = vue.createSSRApp(App);
    return {
      app
    };
  }
  createApp().app.mount("#app");
})(Vue);
